package com.ormlite.activity;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;

import com.ormlite.activity.add.AddEventActivity;
import com.ormlite.activity.add.AddMovieActivity;
import com.ormlite.activity.check.CheckEventActivity;
import com.ormlite.activity.check.CheckMovieActivity;
import com.ormlite.app.R;
import com.ormlite.db.OrmLiteHelper;

public class MainActivity extends Activity {

	private static final Map<Class<?>, Integer> activityToButton;

	static {
		Map<Class<?>, Integer> actToBut = new HashMap<Class<?>, Integer>(4);
		actToBut.put(CheckMovieActivity.class, R.id.checkMovies);
		actToBut.put(AddMovieActivity.class, R.id.addMovie);
		actToBut.put(CheckEventActivity.class, R.id.checkEvents);
		actToBut.put(AddEventActivity.class, R.id.addEvent);
		activityToButton = Collections.unmodifiableMap(actToBut);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		new OrmLiteHelper(this);
		setContentView(R.layout.activity_main);

		for (Class<?> activity : activityToButton.keySet()) {
			this.addListenerOnButton(activity);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	private void addListenerOnButton(final Class<?> activity) {

		findViewById(activityToButton.get(activity)).setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View view) {
				startActivity(new Intent(MainActivity.this, activity));
			}
		});
	}
}
